package com.example.muasic.uitl;

import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

import com.example.muasic.info.Info;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class utils {

    public static int compareList(List<Info> preList,List<Info> nowlist){
        int result=0;
        if(preList.size()!=nowlist.size()){
            Log.d("Panduan","zhixing");
            result= 1;
        }else {
            for (int i = 0; i < preList.size(); i++) {
                long test1 = preList.get(i).getSongId();
                long test2 = preList.get(i).getSongId();
                Log.d("Panduan", "zhixing2" + test1 + "值");
                Log.d("Panduan", "ythiasjdfi2" + test2 + "值");
                if(test1 != test2){
                    Log.d("Panduan", "zhixing4");
                    return 1;
                }

            }
        }
        return result;
    }


    public static List<Bitmap> getImg(Context context,List<Info> List) throws FileNotFoundException {
        List<Bitmap> bitmapList=new ArrayList<>();
        for(int i=0;i<List.size();i++)
       {
            //获取专辑ID
            long albumId = List.get(i).getAlbumId();
            //根据专辑ID获取到专辑封面图
            bitmapList.add(getAlbumArt(context,albumId));
        }

        return bitmapList;  }
    /**
     * 根据专辑ID获取专辑封面图
     * @param album_id 专辑ID
     * @return
     */
    public static Bitmap getAlbumArt(Context context,long album_id) throws FileNotFoundException {
        String mUriAlbums = "content://media/external/audio/albums";
        String[] projection = new String[]{"album_art"};
        Cursor cur = context.getContentResolver().query(Uri.parse(mUriAlbums + "/" + Long.toString(album_id)), projection, null, null, null);
        String album_art = null;
        if (cur.getCount() > 0 && cur.getColumnCount() > 0) {
            cur.moveToNext();
            album_art = cur.getString(0);
        }
        cur.close();
        Bitmap bm = null;
        if (album_art != null) {
            BitmapToRound_Util round_Util = new BitmapToRound_Util();
            bm= round_Util.toRoundBitmap(BitmapFactory.decodeFile(album_art));
        }
        return bm;
    }


}
